﻿using System;
using System.Linq;

namespace Picnic.Spec.Specifications
{
	public class StatementScopeSpec : Specification
	{
		protected override void SpecificationBody()
		{
			Describe<StatementScope>("class", () =>
				It("should not create new instance without a subject", () =>
					((Action)(() => new StatementScope(null, null, null)))
						.ShouldRaise<ArgumentException>()));

			Describe<StatementScope>("instance", () =>
			{
				#region Initialization

				var statement11 = new Statement("Statement1.1", () => { });
				var scope1 = new StatementScope("Subject1", "Context1", new[] { statement11 });

				var statement21 = new Statement("Statement2.1", () => { });
				var statement22 = new Statement("Statement2.2", () => { });
				var scope2 = new StatementScope("Subject2", "Context2", new[] { statement21, statement22 });

				var scope3 = new StatementScope("Subject3", null, new[] { new Statement("Statement3.1", () => { }) });
				var scope4 = new StatementScope("Subject4", string.Empty, new[] { new Statement("Statement4.1", () => { }) });

				#endregion

				It("should have subject specified on instance initialization", () =>
				{
					scope1.Subject.ShouldEquals("Subject1");
					scope2.Subject.ShouldEquals("Subject2");
				});

				It("should have context specified on instance initialization", () =>
				{
					scope1.Context.ShouldEquals("Context1");
					scope2.Context.ShouldEquals("Context2");
				});

				It("should have empty string context if null or empty string specified on instance initialization", () =>
				{
					scope3.Context.ShouldEquals(string.Empty);
					scope4.Context.ShouldEquals(string.Empty);
				});

				It("should have statements specified on initialization", () =>
				{
					scope1.Statements.Count().ShouldEquals(1);
					scope1.Statements.ShouldContains(statement11);

					scope2.Statements.Count().ShouldEquals(2);
					scope2.Statements.ShouldContains(statement21);
					scope2.Statements.ShouldContains(statement22);
				});
			});
		}
	}
}
